<template>
	<view class="fui-wrap">
		<view class="logo">
			<image :src="logo" mode="widthFix"></image>
			<fui-text text="停车场登录" type="black" size="42" block align="center" fontWeight="800"></fui-text>
		</view>
		<fui-form ref="form">
			<fui-segmented-control  @click="changeSegmented" :current="current" :height="84" :values="segmented"></fui-segmented-control>
			<fui-input :size="32" :marginTop="20" :inputBorder="true" placeholder="请输入用户名" v-model="formData.username" :padding="['20rpx','26rpx']"></fui-input>
			<fui-input :size="32" :marginTop="20" type="password" :inputBorder="true" placeholder="请输入密码" v-model="formData.password" :padding="['20rpx','26rpx']"></fui-input>
			<view class="fui-align__center">
				<fui-label>
					<fui-checkbox :scaleRatio="0.8" borderRadius="15%" :checked="checked[2]" @change="changeCheck_2"></fui-checkbox>
					<text class="jizhu">记住账号密码</text>
				</fui-label>
			</view>
			<view class="fui-btn__box">
				<fui-button text="登录" bold @click="submit"></fui-button>
			</view>
		</fui-form>
		<view class="footer">
			<fui-text text=">>>切换到微信绑定账户" @click="$navigateTo('parking/list')" type="warning" decoration="underline" size="28" block align="right"></fui-text>
		</view>
	</view>
</template>

<script>
	import {methods,baseUrl} from '@/utils/core.js';
	export default {
		data() {
			return {
				logo:baseUrl+'assets/img/logo.png',
				checked:[true,true,false],
				segmented:['停车场管理','集团账户'],
				type:['parking','property'],
				current:0,
				formData:{
					username:'',
					password:''
				},
				show:[false,false],
				panelData0: {
					title: '云起智慧停车停车场用户协议',
					desc: ''
				},
				panelData1: {
					title: '云起智慧停车隐私政策',
					desc: ''
				}
			}
		},
		onLoad() {
			let admin=uni.getStorageSync('parking-admin-login')  || '';
			if(admin){
				this.formData={
					username:admin.username,
					password:admin.password
				}
				this.checked[2]=true;
			}
		},
		methods: {
			...methods,
			changeSegmented:function(e){
				this.current=e.index;
			},
			submit:function(){
				if(!this.formData.username.trim()){
					this.$msg('用户名不能为空');
					return;
				}
				if(!this.formData.username.trim()){
					this.$msg('密码不能为空');
					return;
				}
				this.$post('parking/common/login',{type:this.type[this.current],...this.formData},true,true).then(res=>{
					if(this.checked){
						uni.setStorageSync('parking-admin-login',this.formData);
					}else{
						uni.setStorageSync('parking-admin-login','');
					}
					this.$reLaunch('parking/index');
				});
			},
			changeCheck_0:function(e){			
				this.checked[0]=e.checked;
			},
			changeCheck_1:function(e){
				this.checked[1]=e.checked;
			},
			changeCheck_2:function(e){
				this.checked[2]=e.checked;
			}
		}
	}
</script>

<style lang="scss" scoped>
.fui-wrap{
	padding: 30rpx;
}
.fui-btn__box{
	margin-top: 60rpx;
}
.logo{
	display: flex;
	flex-direction: column;
	justify-content: center;
	align-items: center;
	height: 400rpx;
	image{
		width: 200rpx;
		height: 200rpx;
	}
}
.fui-align__center{
	margin-top: 40rpx;
}
.jizhu{
	margin-left: 10rpx;
	font-size: 24rpx;
}
.xieyi{
	margin-left: 10rpx;
	font-size: 24rpx;
	color: #36b1f3;
}
.panel{
	width: 90%;
	margin: 0 auto;
	background-color: #fff;
	height: 1000rpx;
	overflow-y: scroll;
	border-radius: 8rpx;
	padding: 20rpx;
}
.footer{
	margin-top: 100rpx;
}
</style>